<?php

require_once('init.php');

require_once('logowanie.php');
require_once('layout.php');
require_once ('menu.php');
require_once 'pgb/Client/Contact/GatheredInfo.php';
//header("Content-Type: text/html; charset=UTF-8");

if(!isset($_GET['action'])) {
  $_GET['action'] = 'clients';
}
$action = $_GET['action'];

if(!User_Session::isLogIn() || $action=='logout') {
  $form = Wyloguj();  //zrob logout wczesniej niz top!
  $content .= top();
  $content .= frame_bezmenu($form);

  echo $content;
  die();
}

$content = '';
$menu = menu();
try{
  $obj = Module::init( $action );

  //check if is logged first and if user dont logout
  if (User_Session::isLogIn() && $action!="logout" && $obj){
    $modul = new modules( $action );
    $form = $modul->przetworzRzadanie();
  } else {
    throw new Exception();
  }
}
catch( Exception $e ){
  $content .= $e->getMessage();

  switch ($action)
  {
    case "  ": $form = Wyloguj(); break;
    case "sources": require('sources.php'); $form = Sources(); break;
    //case "contacts": require('contacts.php'); $form = Contacts(); break;
    case "potClients": require('potclients.php'); $form=PotClients(); break;
    case "swichUser":
      


      break;
    //case "test": require("test.php"); $form = test();break;
    default: break;
  }
}

if (User_Session::isLogIn() && $action!="logout"){
  $form .= Application::addExternalModulesHtml();
  $content .= top();
  $content .= frame($menu,$form);
}

$content .= bottom();

//Frontend::setContent($content);
echo $content;
//echo Frontend::getOutput();
Application::logCandidatesWithMissingFiles(3);
flush();

//mirroring zapytan na drugi serwer - na samym koncu ale przy logowaniu tez
//include_once 'mirror.php';

